//
//  UIView+Extension.m
//
//  Created by maker on 16/1/10.
//  Copyright © 2017年 刘甲奇. All rights reserved.
//

#import "UIView+Extension.h"

@implementation UIView (Extension)

#pragma mark =================== setter ===================

- (void)setLeft:(CGFloat)left
{
    CGRect frame = self.frame;
    frame.origin.x =left;
    self.frame = frame;
}
- (void)setRight:(CGFloat)right
{
    CGRect frame = self.frame;
    frame.origin.x = right - frame.size.width;
    self.frame = frame;
}
- (void)setTop:(CGFloat)top
{
    CGRect frame = self.frame;
    frame.origin.y =top;
    self.frame = frame;
}
- (void)setBottom:(CGFloat)bottom
{
    CGRect frame = self.frame;
    frame.origin.y = bottom - frame.size.height;
    self.frame = frame;
}


- (void)setSize:(CGSize)size
{
    CGRect frame = self.frame;
    frame.size =size;
    self.frame = frame;
}

- (void)setWidth:(CGFloat)width
{
    CGRect frame = self.frame;
    frame.size.width =width;
    self.frame = frame;
}
- (void)setHeight:(CGFloat)height
{
    CGRect frame = self.frame;
    frame.size.height =height;
    self.frame = frame;
}


- (void)setCenterX:(CGFloat)centerX {
    self.center = CGPointMake(centerX, self.center.y);
}
- (void)setCenterY:(CGFloat)centerY {
    self.center = CGPointMake(self.center.x, centerY);
}

#pragma mark =================== getter ===================

- (CGFloat)left
{
    return self.frame.origin.x;
}
- (CGFloat)right
{
    return self.frame.origin.x + self.frame.size.width;
}
- (CGFloat)top
{
    return self.frame.origin.y;
}
- (CGFloat)bottom
{
    return self.frame.origin.y + self.frame.size.height;
}


- (CGSize)size
{
    return self.frame.size;
}
- (CGFloat)width
{
    return self.frame.size.width;
}
- (CGFloat)height
{
    return self.frame.size.height;
}


- (CGFloat)centerX {
    return self.center.x;
}
- (CGFloat)centerY {
    return self.center.y;
}

#pragma mark =================== 从 nib 中加载 view ===================
+ (UIView *)getNibView:(NSString *)nibName
{
    return [[NSBundle mainBundle] loadNibNamed:nibName owner:nil options:nil].firstObject;
}
@end












